﻿// <copyright file="TTableEntityTransactionInfo.cs" company="N/A">
//     Copyright (c) Nicholas Barrett and Benjamin Kasten.  All rights reserved.
//
//     This program is free software; you can redistribute it and/or modify it
//     under the terms of the GNU General Public License as published by the
//     Free Software Foundation; either version 2 of the License, or (at your
//     option) any later version.
//
//     This program is distributed in the hope that it will be useful, but
//     WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
//     Public License for more details.
//
//     You should have received a copy of the GNU General Public License along
//     with this program; if not, write to the Free Software Foundation, 
//     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// </copyright>

namespace BetterAzureTableStorage
{
    using System;
    using System.Collections.Generic;
    using System.Data.Services.Client;
    using System.Linq;
    using System.Net;
    using System.Text;

    /// <summary>
    /// EntityInfo contains information about the tracking/storage of entities in
    /// TableStorageDataContext.
    /// </summary>
    public class TTableEntityTransactionInfo
    {
        /// <summary>
        /// Gets or sets the entity described in this instance.
        /// </summary>
        /// <value>The entity.</value>
        public ITableEntity Entity { get; set; }

        /// <summary>
        /// Gets or sets the content ID.
        /// </summary>
        /// <value>The content ID.</value>
        /// <remarks>
        /// This is used to link the individual batched responses to an EntityInfo/Entity
        /// </remarks>
        public int ContentID { get; set; }

        /// <summary>
        /// Gets or sets the state of the entity.
        /// </summary>
        /// <value>The state of the entity.</value>
        /// <remarks>
        /// Added, Deleted, Modified, etc...
        /// </remarks>
        public EntityStates State { get; set; }

        /// <summary>
        /// Gets or sets the HTTP method for a request.
        /// </summary>
        public string Verb { get; set; }

        /// <summary>
        /// Gets or sets the response StatusCode that indicates success.
        /// </summary>
        public HttpStatusCode SuccessCode { get; set; }

        /// <summary>
        /// Gets or sets an action to execute upon success.
        /// </summary>
        public Action<TTableEntityTransactionInfo> OnSuccess { get; set; }

        /// <summary>
        /// Gets or sets an action to execute upon failure.
        /// </summary>
        public Action<TTableEntityTransactionInfo> OnFailure { get; set; }

        /// <summary>
        /// Gets or sets the most recent exception associated with the entity.
        /// </summary>
        /// <value>null if no exception has occurred</value>
        public Exception Error { get; set; }

        /// <summary>
        /// Gets or sets the name of the entity set.
        /// </summary>
        /// <value>The name of the entity set.</value>
        /// <remarks>
        /// This is the name of the table that the entity is persisted in.
        /// </remarks>
        public string SetName { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="TTableEntityTransactionInfo"/> class.
        /// </summary>
        /// <param name="entity">The entity described by this instance.</param>
        /// <param name="state">The initial state of the entity.</param>
        public TTableEntityTransactionInfo(ITableEntity entity, EntityStates state)
        {
            this.Entity = entity;
            this.State = state;
        }
    }
}
